﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using LitJson;

public class DataManager : Single<DataManager>
{
    public Dictionary<int, Enemy> enemdic = new Dictionary<int, Enemy>();

    public void DataInit()
    {
        Initdate();
    }

    private void Initdate()
    {
        string text = DataManager.GetInstance.LoadFile("Enemyconfig");
        JsonData data = JsonMapper.ToObject(text);

        for (int i = 0; i < data.Count; i++)
        {
            Enemy enemy = new Enemy();
            enemy.id = int.Parse(data[i][0].ToString());
            enemy.name = data[i][1].ToString();
            enemy.hp = int.Parse(data[i][2].ToString());
            enemy.demage = int.Parse(data[i][3].ToString());
            enemy.enempath = data[i][4].ToString();
            enemdic.Add(enemy.id, enemy);
        }
    }

    Dictionary<string, GameObject> m_dicgameobject = new Dictionary<string, GameObject>();


    //加载预置体
    public GameObject Loadasset(ResourcesEnum restype, string name)
    {

        if (m_dicgameobject.ContainsKey(name))
        {
            return m_dicgameobject[name];
        }
        string path = "";
        switch (restype)
        {
            case ResourcesEnum.config:
                path = "config/";
                break;
            case ResourcesEnum.Prefab:
                path = "Prefab/";
                break;
            case ResourcesEnum.Sprites:
                path = "Sprites/";
                break;
        }
        path += name;

        GameObject game = Resources.Load(path) as GameObject;

        m_dicgameobject.Add(name, game);

        return game;
    }
    public string LoadFile(string name)
    {
        string path = "config/" + name;

        TextAsset file = Resources.Load<TextAsset>(path);
        if (file == null)
            return null;
        return file.text;
    }




    public GameData gameData = new GameData();
}
public class GameData
{
    public int topscore;
    public int toplevel;
    public List<string> imagepath = new List<string>();
    public int easynum;
    public int zhongdnum;
    public int knNum;
    public List<string> easyname = new List<string>();
    public List<string> zhongdname = new List<string>();
    public List<string> knname = new List<string>();
    public List<string> scenepath = new List<string>();

}
//预质体枚举
public enum ResourcesEnum
{
    None,
    config,
    Prefab,
    Sprites,
}
//界面枚举
public enum WindowsEnum
{
    None,
    Panle
}

//公共类
public class Const
{
    public static bool firstload = true;
    public static int CurrentID = 0;

    public static bool firstinitload = true;
    public static bool isfirstload = true;
    public static int LoadBgid;

    public static bool isgameover = false;

    public static bool isbefore = false;

    public static bool isjx = false;

    public static bool isfirstSt = true;

    public static bool isfirstcon = true;
}

public class RandomNum
{
    static int number;
    //获取随机数
    public static int GetRandomNum(int max, int min)
    {
        int num = Random.Range(min, max);
        if (number != num)
        {
            number = num;
        }
        else
        {
            GetRandomNum(max, min);
        }
        return number;
    }
}